//
//  FDSetingController.m
//  FamousDoctorOnline
//
//  Created by wszyxc on 16/7/5.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDSetingController.h"
#import "FDSuggestingController.h"

#import "JASidePanelController.h"
#import "FDLeftController.h"

#import "FDModifyPasswordController.h"

@interface FDSetingController ()<UITableViewDelegate,UITableViewDataSource>


@property (nonatomic,strong)UITableView *tableview;
@property (nonatomic,strong)NSArray *settingArr;

@end

@implementation FDSetingController

-(NSArray *)settingArr
{
    if(_settingArr  == nil)
    {
        _settingArr = @[@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户"];
        
    }
    return _settingArr;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTableView];
    
}

-(void)setupTableView
{
    UITableView *tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height- self.navigationController.navigationBar.height) style:UITableViewStylePlain];
    
    self.tableview = tableview;
    
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    [self.view addSubview:tableview];
    
    self.tableview.tableFooterView = [[UIView alloc]init];
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectio{
    return self.settingArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setting"];
    if(!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"setting"];
        
    }
    
    cell.textLabel.text = self.settingArr[indexPath.row];
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return  0.01;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        FDSuggestingController *suggest = [[FDSuggestingController alloc]init];
        
        [self.navigationController pushViewController:suggest animated:YES];
    }else if (indexPath.row == 2){
        //修改密码
        FDModifyPasswordController *modifyVC = [[FDModifyPasswordController alloc]init];
        
        [self.navigationController pushViewController:modifyVC animated:YES];
        
    }
    
    else if(indexPath.row == 3){
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否确认注销" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            NSUserDefaults *defult = [NSUserDefaults standardUserDefaults];
            [defult setBool:NO forKey:@"isLogin"];
            
            //用户资料内容的刷新
            
            
           JASidePanelController *jaVC =  (JASidePanelController *)[UIApplication sharedApplication].keyWindow.rootViewController;
            
            FDLeftController *leftVC = (FDLeftController *)jaVC.leftPanel;
            
            leftVC.isLogin = NO;
            
            
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
        
        [self presentViewController:alert animated:YES completion:nil];
    }
    
    
    
}

//消除tableView下面的线

//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//    
//    UIView *view = [[UIView alloc]init];
//    
//    view.backgroundColor = [UIColor clearColor];
//    
//    return view;
//    
//}


@end
